package com.jk.web.controller;

import com.jk.common.model.AddressBean;
import com.jk.common.model.OrderBean;
import com.jk.web.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.awt.*;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("shop")
public class ShoppingController {

    @Autowired
    private ShopService shopService;

    /**
     * 新增收货人地址
     */
    @RequestMapping("saveUserAddress")
    @ResponseBody
    public  void saveUserAddress(AddressBean addressBean, HttpSession session){
     /*   String id = session.getId();
        addressBean.setUserId(id);*/
        shopService.saveUserAddress(addressBean);
    }

    /**
     * 订单生成id    前台ajax 生成
     * @param orderBean  订单Id
     * @param flowers  鲜花id 有可能有多个
     * @return
     */
    @RequestMapping("generateOrderId")
    @ResponseBody
    public  Map generateOrderId(String userId,String flowerIds){

       Map map=shopService.generateOrderId(userId, flowerIds);

        return map;
    }

    /**
     * 订单提交
     */
    @RequestMapping("orderSave")
    @ResponseBody
    public  Boolean orderSave(OrderBean orderBean){
            try {
             shopService.orderSave(orderBean);
                return  true;
            }catch (Exception e){
                e.printStackTrace();
                return  false;
            }

    }

    /**
     * 查询收货人地址
     * @param userId
     * @return
     */
    @RequestMapping("findUserAddress")
    @ResponseBody
    public AddressBean findUserAddress(String userId){

        AddressBean plist=  shopService.findUserAddress(userId);
        return  plist;
    }


}
